package org.hyh.core.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.hyh.core.mapper.SysUserMapper;
import org.hyh.core.model.entity.SysUser;
import org.hyh.core.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

/**
 * @auther :hyh
 * @desc :
 * @date :2020/7/11
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    SysUserMapper userMapper;
    @Autowired
    BCryptPasswordEncoder bCryptPasswordEncoder;

    @Override
    public SysUser getUserByUsernamePassword(String username, String password) {
        QueryWrapper<SysUser> queryWrapper =new QueryWrapper<>();
         queryWrapper.lambda().eq(SysUser::getPassword,bCryptPasswordEncoder.encode(password))
                              .eq(SysUser::getUsername,username);
        SysUser sysUser = userMapper.selectOne(queryWrapper);
        return  sysUser;
    }

}
